<?php

namespace App\Http\Controllers\Mobile;

use App\Models\Shop;
use Illuminate\Support\Facades\Auth;

class KefuController extends BaseController
{
    //
    public function index()
    {

    }

    public function bind($shop_id)
    {
        $shop = Shop::find($shop_id);
        $kefu = $shop->kefus()->where('uid', $this->uid)->first();
        return $this->view('mobile.kefu.bind', compact('shop_id', 'shop', 'kefu'));
    }

    public function bindKefu()
    {
        $shop_id = $this->request->input('shop_id');
        $kefu = Shop::find($shop_id)->kefus()->create([
            'uid'=>$this->uid,
            'name'=>$this->username,
            'openid'=>Auth::user()->connect->openid,
            'created_at'=>time()
        ]);
        return ajaxReturn(['kefu'=>$kefu]);
    }
}
